package com.aps.server.controller;

import com.aps.common.code.DistributedSnowflakeIdGenerator;
import com.aps.common.entity.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author nbZhuozh
 * @Date 2025-10-17  11:23
 **/

@RestController
@RequestMapping("/api/code-generator")
public class CodeGeneratorController {

    /**
     * 生成编码
     * @param prefix
     * @return
     */
    @GetMapping("gen")
    public Result<String> gen(@RequestParam(name = "prefix" , required = false) String prefix) {
        if(StringUtils.isEmpty(prefix)){
            return Result.success(DistributedSnowflakeIdGenerator.generate20DigitId());
        }
        return Result.success(prefix + DistributedSnowflakeIdGenerator.generate20DigitId());
    }



}
